package Task;

/**
 * Created with IntelliJ IDEA.
 * Description: Java多线程实验四代码
 */


public class Test4 extends Thread{
    private int num = 0;
    private static int sum = 0;
    private Test4(int num) {
        this.num = num;
    }
    private synchronized void add(int num) {
        this.sum += num;
    }
    @Override
    public void run() {
        int sum = 0;
        for (int i = 0; i < 10; i++) {
            sum += num + i;
        }
        add(sum);
    }

    public static void main(String[] args) throws InterruptedException {
        Thread[] thread = new Test4[10];
        for (int i = 0; i < 10; i++) {
            thread[i] = new Test4(i * 10 + 1);
            thread[i].start();
        }
        for (int i = 0; i < 10; i++) {
            thread[i].join();
        }
        System.out.println(sum);
    }
}
